package com.example.exam.utils;

import com.amazonaws.util.Md5Utils;
import lombok.extern.log4j.Log4j2;

import java.util.UUID;

/**
 * @author zhang
 */
@Log4j2
public class FileUtils {
    public static String isOneFile(byte[] file) {
        return Md5Utils.md5AsBase64(Md5Utils.computeMD5Hash(file));
    }

    public static String fileNameToUuid(String fileName) {
        if (!fileName.contains(".")) {
            return null;
        }
        return UUID.randomUUID() + String.valueOf((System.currentTimeMillis() % 1000)) + fileName.substring(fileName.lastIndexOf("."));
    }
    //检查文件是否是excel

    public static boolean isExcel(String fileName) {
        return fileName.endsWith(".xls") || fileName.endsWith(".xlsx");
    }
}
